package CodeProcess;

import java.text.DecimalFormat;

/**
 * 管外径处理器
 *
 * @author zzy
 * @version V1.0
 * @since 2022/8/3
 */
public class DiameterProcess extends ProjectCodeProcess {

    public String process(String[] args) {

        final String D_T = "管外径";
        final String D_T_T = "内管外径";

        // 焊接位置下标
        // int index = ProjectCodeProcess.getPositionIndex(args);

        // 试件形式
        String specimen = args[1];

        // 焊缝形式
        // String gap = args[2];

        // 3.6.2 焊工采用管试件进行技能评定合格后，管外径的适用范围见表 10。对于管-管角焊缝（套管），D 为内管外径值
        if ("T".equals(specimen)) {
            return D_T;
        }
        else if ("T-T".equals(specimen)) {
            return D_T_T;
        }
        else if ("P-T".equals(specimen)) {
            return D_T;
        }

        return null;
    }

    public String processName(Float[] params) {

        if (params[3] == null) {
            return "D" + replace(params[1].toString()) + "/"
                    + replace(params[2].toString());
        }

        else {
            return "D" + replace(params[1].toString()) + "/"
                    + replace(params[2].toString()) + "\t"
                    + replace(params[3].toString()) + "°";
        }

    }

    public String processMeaning(Float[] params) {
        // 取两位小数
        DecimalFormat df = new DecimalFormat("0.00");
        float num = params[1] / params[2];

        if (params[3] == null) {
            return "主管外径" + replace(params[1].toString()) + "mm" + "\t"
                    + "支管外径" + replace(params[2].toString()) + "mm" + "\t"
                    + "D1/D2=" + replace(df.format(num));
        }

        else {
            return "主管外径" + replace(params[1].toString()) + "mm" + "\t"
                    + "支管外径" + replace(params[2].toString()) + "mm" + "\t"
                    + "D1/D2=" + replace(df.format(num)) + "\t"
                    + "主管与支管角度为" + replace(params[3].toString()) + "°";
        }

    }

    public String processSuit(Float[] params) {
        // 取两位小数
        DecimalFormat df = new DecimalFormat("0.00");
        float num = params[1] / params[2];

        // 支管外径
        Float d = params[2];
        // 支管外径计算
        String str = "";

        if (d < 25) {
            str = d + "~" + 2 * d + "mm";
        }
        if (d >= 25 && d < 76) {
            str = "≥25mm";
        }
        if (d >= 76) {
            str = "≥76mm";
        }

        if (params[3] == null) {
            return "支管外径：" + replace(str) + "\t"
                    + "D1/D2≥" + replace(df.format(num));
        }

        else {
            return "支管外径：" + replace(str) + "\t"
                    + "D1/D2≥" + replace(df.format(num)) + "\t"
                    + "支管角度>=" + replace(params[3].toString()) + "°";
        }
    }

}
